<template>
  <view :style="style" />
</template>
<script>
export default {
  data() {
    return {
      /* 设定状态栏默认高度 */
      statusBarHeight: 20,/* 状态栏高度 */
      navBarHeight: 45,/* 导航栏高度 */
      windowWidth: 375,/* 窗口宽度 */
    };
  },
  computed: {
    style() {
      var StatusBarHeight= this.statusBarHeight;
      var NavBarHeight= this.navBarHeight;
      var style = "";
      // 除了h5、app、mp-alipay三个的情况下执行，区别ifdef
      // #ifndef H5 || APP-PLUS || MP-ALIPAY
      style = `${style}margin-top:${StatusBarHeight+NavBarHeight}px;`;
      // #endif
      return style
    }
  },
  created() {
    let statusBarObj = this.liuHaiP()
    this.statusBarHeight = statusBarObj.statusBarHeight
    this.navBarHeight = statusBarObj.navBarHeight
    this.windowWidth = statusBarObj.windowWidth
  },
  methods:{
    //看手机是否为刘海屏
    liuHaiP(){
      // 获取手机系统信息
      const systemInfo = uni.getSystemInfoSync()
      let statusBarObj = {
        isFit: false,
        statusBarHeight: 20,/* 状态栏高度 */
        navBarHeight: 45,/* 导航栏高度 */
        windowWidth: 375,/* 窗口宽度 */
      }
      // 设置状态栏高度（H5顶部无状态栏小程序有状态栏需要撑起高度）
      statusBarObj.statusBarHeight = systemInfo .statusBarHeight
      statusBarObj.windowWidth = systemInfo .windowWidth
      // 除了h5、app、mp-alipay的情况下执行
      // #ifndef H5 || APP-PLUS || MP-ALIPAY
      // 获取胶囊的位置
      const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
      // (胶囊底部高度 - 状态栏的高度) + (胶囊顶部高度 - 状态栏内的高度) = 导航栏的高度
      statusBarObj.navBarHeight = (menuButtonInfo.bottom - systemInfo .statusBarHeight) + (menuButtonInfo.top - systemInfo .statusBarHeight)
      statusBarObj.windowWidth = menuButtonInfo.left
      // #endif
      return statusBarObj
    }
  }
}
</script>

<style>

</style>

